package API.RegexDome;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * ClassName:RegexText009
 * Package:API.RegexDome
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/1-18:55
 * @Version:v1.0
 */
public class RegexText009 {
    /*
    * 扩展需求
    * 把链接：https://m.sengzan.com/jiaoyu/29104.html?ivk_sa=1025883i
    * 中的所有的身份证号码都爬出来
    * */
    public static void main(String[] args) throws IOException {
        //创建一个URL对象
        URL url = new URL("https://pvp.qq.com/web201605/herolist.shtml");
        //连接上这个网址
        URLConnection conn = url.openConnection();
        //创建一个对象去读取网络中的数据
        BufferedReader  br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = br.readLine())!=null){
            System.out.println(line);
            //获取正则表达式的对象
            String regex = "[1-9]\\d{6}";
            String regex1 ="";
            Pattern pattern = Pattern.compile(regex);
            //读取的时候每次读取一整行
            while ((line = br.readLine())!=null){
                //拿着文本匹配器的对象matcher按照pattern的规则去读取当前的这一行信息
                Matcher matcher = pattern.matcher(line);
                while (matcher.find()){
                    System.out.println(matcher.group());
                }
            }
//            br.close();
        }
    }
}
